package netbay;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.Channel;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import util.jQgrid.JQGridRow;

public class TransactionManager {

	public static String jdbcDriver = "";
	public static String dbUrl = "";
	public static String dbUser = "";
	public static String dbPassword = "";

	public static String JPMCcpaId = "";
	public static String JPMCService = "";
	public static String JPMCTransportProtocol = "";
	public static String JPMCTransportEndPoint = "";
	public static String JPMCPayloadType = "";

	public static String recvTcdStatus = "";
	public static String recvRdStatus = "";
	public static String beginSendJpmcStatus = "";
	public static String finSendJpmcStatus = "";
	public static String recvJpmcStatus = "";
	public static String sendTcdStatus = "";
	public static String sendRdStatus = "";
	public static String resendSFTPStatus = "";
	public static String redownloadSFTPStatus = "";
	public static String redownloadSFTPRDStatus = "";
	public static String resendFinSFTPStatus = "";
	public static String redownloadFinSFTPStatus = "";
	public static String finSendTcdStatus = "";
	public static String finSendRdStatus = "";
	public static String beginSendJpmcStatusRD;
	public static String finSendJpmcStatusRD;
	public static String recvJpmcStatusRD;
	public static String resendSFTPStatusRD;
	public static String redownloadSFTPStatusRD;
	public static String resendFinSFTPStatusRD;
	public static String redownloadFinSFTPStatusRD;

	public TransactionManager() {

		super();

	}

	//find transaction log by xml file that transaction have finish send jpmc status
	//use by recvJPMC()
	public TransactionLog findTransactionByAttach(String attachName) {
		Connection con = null;
		// String[] cut = attachName.split("[_-.]");
		String[] cut = attachName.split("[--.]");
		if (cut.length > 2) {
			String converId = cut[1];
			
			try {
				con = getConnection();
				PreparedStatement st = TransactionLog.convertFindDoneByConverId(
						converId, con);
				if (st != null) {
					ResultSet rs = st.executeQuery();
					return TransactionLog.convertResultsetToLog(rs);
				}

			} catch (SQLException e) {
				e.printStackTrace();
			//nat add finally
			}finally {
				if (con != null) {
					try {
						con.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}
		}
		return null;
	}
	
	//find traffic log by transactionid that traffic will have finish send jpmc status, max time of that status
	//use by recvJPMC(), ReTCDTCD
	public TransactionTraffic findTraffJpmcAttachByTransactionId(Integer transactionId) {
		Connection con = null;

			try {
				con = getConnection();
				PreparedStatement st = TransactionTraffic.convertFindByTransactionId(
						transactionId, con);
				if (st != null) {
					ResultSet rs = st.executeQuery();
					return TransactionTraffic.convertResultsetToLog(rs);
				}

			} catch (SQLException e) {
				e.printStackTrace();
			//nat add finally
			}finally {
				if (con != null) {
					try {
						con.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}
		return null;
	}
	
	public TransactionTraffic findTraffJpmcAttachByTransactionIdForResend(Integer transactionId) {
		Connection con = null;

			try {
				con = getConnection();
				PreparedStatement st = TransactionTraffic.convertFindByTransactionIdForResend(
						transactionId, con);
				if (st != null) {
					ResultSet rs = st.executeQuery();
					return TransactionTraffic.convertResultsetToLog(rs);
				}

			} catch (SQLException e) {
				e.printStackTrace();
			//nat add finally
			}finally {
				if (con != null) {
					try {
						con.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}
		return null;
	}
	
	//find traffic log by transactionid that traffic will have finish send tcd status, max time of that status
	//use by recvJPMC(), ReTCDTCD
	public TransactionTraffic findTraffSendTCDByTransactionId(Integer transactionId) {
		Connection con = null;

			try {
				con = getConnection();
				PreparedStatement st = TransactionTraffic.convertFindTraffSendTCDByTransactionId(
						transactionId, con);
				if (st != null) {
					ResultSet rs = st.executeQuery();
					return TransactionTraffic.convertResultsetToLog(rs);
				}

			} catch (SQLException e) {
				e.printStackTrace();
			//nat add finally
			}finally {
				if (con != null) {
					try {
						con.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}
		return null;
	}
	
	public TransactionTraffic findTraffSendRDByTransactionId(Integer transactionId) {
		Connection con = null;

			try {
				con = getConnection();
				PreparedStatement st = TransactionTraffic.convertFindTraffSendRDByTransactionId(
						transactionId, con);
				if (st != null) {
					ResultSet rs = st.executeQuery();
					return TransactionTraffic.convertResultsetToLog(rs);
				}

			} catch (SQLException e) {
				e.printStackTrace();
			//nat add finally
			}finally {
				if (con != null) {
					try {
						con.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}
		return null;
	}

	
	//find traffic by transactionid
	//use by TrafficViewerServlet
	public List getDisplayTraffic(Integer transactionId,String page,
			String limit, String sidx, String sord) throws Exception {

		Connection con = null;
		List resultList = null;
		try {

			con = getConnection();
			PreparedStatement st = TransactionTraffic.convertFindTraffic(transactionId,page, limit, sidx, sord,
					con);

			if (st != null) {
				ResultSet rs = st.executeQuery();

				resultList = TransactionTraffic
						.convertResultsetTrafficToDisplay(rs);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new Exception("Cannot display TCD traffic");
			//return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return resultList;
	}
	
	
	//find count success file group by time send from condition
	//use by TCDBillingServlet
	public List getDisplayBilling(String fromTime,String toTime,String organize,String page,
			String limit, String sidx, String sord)throws Exception {

		Connection con = null;
		List resultList = null;
		try {

			con = getConnection();
			PreparedStatement st = TransactionTraffic.convertFindBilling(fromTime,toTime,organize,page, limit, sidx, sord,
					con);

			if (st != null) {
				ResultSet rs = st.executeQuery();

				resultList = TransactionTraffic
						.convertResultsetBillingToDisplay(rs);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new Exception("Cannot display Billing");
			//return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return resultList;
	}
	
	//find count success file send from condition
	//use by TCDBillingServlet
	public Integer getDisplayBilling(String fromTime,String toTime,String organize)throws Exception {

		Connection con = null;
		Integer count = 0;
		try {

			con = getConnection();
			PreparedStatement st = TransactionTraffic.convertCountBilling(fromTime,toTime,organize,
					con);

			if (st != null) {
				ResultSet rs = st.executeQuery();
				if(rs.next()){
					count = rs.getInt("sum");
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new Exception("Cannot display Billing");
			//return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return count;
	}
	
	//find conversationid that has send tcd status
	//use by updateDb
	public List findNotUpdateTransaction() {

		Connection con = null;
		List resultList = null;
		try {

			con = getConnection();
			PreparedStatement st = TransactionLog.sqlFindNotUpdateTransaction(con);

			if (st != null) {
				ResultSet rs = st.executeQuery();

				resultList = TransactionLog
						.convertResultsetNotUpdateToList(rs);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return resultList;
	}
	
	//count time that has resend file by xml file (all JPMC and TCD)
	//use by ResendFileServlet
	public List getDisplayResendTCD(List<String[]> xmlFile, String type,String page,
			String limit, String sidx, String sord) throws Exception {
		Connection con = null;
		PreparedStatement st = null;
		ResultSet rs = null;
		List displayList = new ArrayList();
		JQGridRow row;
		try {
			con = getConnection();
			
			for(int i = 0;i<xmlFile.size();i++){
				st = TransactionTraffic.convertFindResendTCD(xmlFile.get(i)[0],type,page, limit, sidx, sord,
						con);
				if (st != null) {
					rs = st.executeQuery();
					if(rs.next()){
						row = new JQGridRow();
						String date;
						
						File file;
						List display = new ArrayList();
						
						String name = xmlFile.get(i)[0];
						String size = xmlFile.get(i)[1];
						display.add(name);
						if(type.equals("jpmc"))display.add(Worker.convertTCDToJPMC(name));
						else display.add(name);
						if(type.equals("jpmc")){
							date = name.substring(13, 30);
							date = changeStringToDateFormatJPMC(date);
						}else if(type.equals("jpmcrd")){
							date = name.substring(22, 36);
							date = changeStringToDateFormatTCD(date);
						}
						else {
							date = name.toString().substring(22, 36);
							date = changeStringToDateFormatTCD(date);
						}
						display.add(date);
						display.add(size+"K");
						display.add(Integer.toString(rs.getInt("sum")));
						
						row.setCell(display);
						displayList.add(row);
					}
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new Exception("Cannot display file.");
			//return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return displayList;
	}
	
	//find count traffic by transactionId
	//use by TrafficViewerServlet
	public Integer getCountTraffic(Integer transactionId) throws Exception {

		Connection con = null;
		Integer count = null;
		try {

			con = getConnection();
			PreparedStatement st = TransactionTraffic.convertCountTraffic(transactionId,
					con);

			if (st != null) {
				ResultSet rs = st.executeQuery();
				if(rs.next()){
					count = rs.getInt("sum");
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new Exception("Cannot display TCD traffic");
			//return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return count;
	}
	
	//find transactionId by converId 
	//use by ReDoServlet, TrafficViewerServlet, TrafficViewerServeltRD
	public Integer getTransactionId(String converId) {

		Connection con = null;
		Integer transactionId = null;
		try {

			con = getConnection();
			PreparedStatement st = TransactionLog.sqlGetTransactionIdByConverId(converId,con);

			if (st != null) {
				ResultSet rs = st.executeQuery();
				if(rs.next()){
					transactionId = rs.getInt("id");
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return transactionId;
	}
	
	//find transction log by converId
	//use by recvTCD, updateTrackToDb()
	public TransactionLog findTransactionByConverId(String ConverId) {
		TransactionLog log = new TransactionLog();
		Connection con = null;
		try {
			con = getConnection();
			PreparedStatement st = TransactionLog.convertFindByConverId(
					ConverId, con);
			if (st != null) {
				ResultSet rs = st.executeQuery();
				return TransactionLog.convertResultsetToLogFindTransactionById(rs);
			}else{
				return log;
			}
			

		} catch (SQLException e) {
			e.printStackTrace();
		//nat add finally
		}finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return log;
	}

	//find id that save transaction by log
	//use by recvTCD()
	public Integer saveTransaction(TransactionLog log) {
		Connection con = null;
		Integer id = null;
		ResultSet rs = null;
		try {

			con = getConnection();
			Statement st = con.createStatement();
			
			String query = TransactionLog.convertInsert(log);
			if(query != null){
				st.execute(query, Statement.RETURN_GENERATED_KEYS);
	
				rs = st.getGeneratedKeys();
	
				if (rs.next()) {
					id = rs.getInt(1);
				}
			}else{
				return null;
			}

		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return id;
	}

	
	public String[] getCtrlToResend(String converId) {

		Connection con = null;
		String[] result = { "", "" };
		try {

			con = getConnection();
			PreparedStatement st = TransactionLog.findCtrlToResend(converId,
					con);

			if (st != null) {
				ResultSet rs = st.executeQuery();
				while (rs.next()) {
					result[0] = Integer.toString(rs.getInt("id"));
					result[1] = (String) rs.getObject("tcdctrl");
				}
				return result;
			}

		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return result;
	}
	
	public int getDisplayTransaction(String fromTime,String toTime,String type,String status,String converID,String organize)throws Exception {

		Connection con = null;
		List resultList = null;
		int count=0;
		try {

			con = getConnection();
			PreparedStatement st = TransactionLog.convertFindByCondition(fromTime,toTime,type,status,converID,organize,con);

			if (st != null) {
				ResultSet rs = st.executeQuery();
				while (rs.next()) {
				 count = rs.getInt("sum");
				}
			}

		} catch (SQLException e) {
			e.printStackTrace();
			throw new Exception("Cannot display transaction");
			//return count;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
					
				}
			}
		}
		return count;
	}
	
	
	
	public List getDisplayTransaction(String fromTime,String toTime,String type,String status,String converID,String reJPMCTCD,String reTCDTCD,
			String organize,String page,String limit, String sidx, String sord)throws Exception {

		Connection con = null;
		List resultList = null;
		try {

			con = getConnection();
			PreparedStatement st = TransactionLog.convertFindByCondition(fromTime,toTime,type,status,converID,organize,page,limit,sidx,sord, con);

			if (st != null) {
				ResultSet rs = st.executeQuery();

				resultList = TransactionLog.convertResultsetToDisplay(rs,reJPMCTCD,reTCDTCD);
			}

		} catch (SQLException e) {
			e.printStackTrace();
			throw new Exception("Cannot display transaction");
			//return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return resultList;
	}

	public static Timestamp convertDoubleToTimestamp (String dbl){
		Connection con = null;
		Timestamp timestamp = null;
		try {

			con = getConnection();
			PreparedStatement st = TransactionLog.convertToTimestamp(dbl, con);

			if (st != null) {
				ResultSet rs = st.executeQuery();

				if(rs.next()){
					timestamp = rs.getTimestamp("timestamp");
				}
				
			}

		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return timestamp;
	
	}
	public boolean resendSFTPById(Integer id) {

		TransactionLog log = findTransactionById(id);
		// need to logging for event resend

		return true;
	}

	public boolean redownloadSFTPById(Integer id) {

		TransactionLog log = findTransactionById(id);
		// need to logging for event redownload

		return true;
	}

	public TransactionLog findTransactionById(Integer id) {
		Connection con = null;
		List resultList = null;
		TransactionLog searchLog = null;

		try {
			con = getConnection();
			Statement stmt = con.createStatement();
			PreparedStatement st = TransactionLog.convertFindById(id, con);
			if (st != null) {
				ResultSet rs = st.executeQuery();
				searchLog = TransactionLog.convertResultsetToLogFindTransactionById(rs);
			}

		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return searchLog;
	}

	public static Connection getConnection() throws SQLException {

		try {
			Class.forName(jdbcDriver);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}

		Connection con = DriverManager.getConnection(dbUrl
				+ "?useUnicode=true&characterEncoding=utf-8", dbUser,
				dbPassword);
		return con;
	}

	public boolean insertArchivedToDB(File archive, Integer transactionId) {
		FileInputStream fis = null;
		boolean Succeed = false;
		Connection con = null;
		try {
			con = getConnection();
			PreparedStatement st = con
					.prepareStatement("insert into archived(id,transactionid,filename,filecontent) values(NULL,?,?,?)");

			if (st != null) {
				st.setInt(1, transactionId);
				st.setString(2, archive.getName());
				fis = new FileInputStream(archive);
				st.setBinaryStream(3, (InputStream) fis, (int) (archive
						.length()));

				st.executeUpdate();

				Succeed = true;
			}

		} catch (SQLException e) {
			e.printStackTrace();
			Succeed = false;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			Succeed = false;
		} finally {
			//nat add finally con
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (fis != null)
				try {
					fis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}

		return Succeed;
	}

	
	public boolean insertTraffic(TransactionTraffic traff) {
		Connection con = null;
		try {
			con = getConnection();
			PreparedStatement st = traff.convertInsert(traff,con);
			if (st != null) {
				st.executeUpdate();

				return true;
			}

		} catch (SQLException e) {
			e.printStackTrace();
			return false;
			//nat add finally
		}finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return false;

	}

	//update transaction status by log(id)
	//use by setTimeEntry
	public boolean updateStatus(TransactionLog log, String status) {
		log.setStatus(status);
		Connection con = null;
		try {
			con = getConnection();
			PreparedStatement st = log.convertUpdateStatus(con);
			if (st != null) {
				st.executeUpdate();

				return true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
			//nat add finally
		}finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return false;
	}
	
	//update finish send file to TCD
	//use by updateTrackToDb
	public boolean updateTransactionStatusFromGateway(String conversationid,String type) {
		Connection con = null;
		try {
			con = getConnection();
			PreparedStatement st = TransactionLog.sqlUpdateTransactionStatus(conversationid ,type,con);
			if (st != null) {
				st.executeUpdate();

				return true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
			//nat add finally
		}finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return false;
	}
	
	public boolean insertTrafficStatus(TransactionTraffic traff) {
		Connection con = null;
		try {
			con = getConnection();
			PreparedStatement st = TransactionTraffic.convertInsert(traff,con);
			if (st != null) {
				st.executeUpdate();
				return true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
			//nat add finally
		}finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return false;
	}
	
	public static String getCurTimeDecimal(){
		Date now2  = new Date();
		String dateStr ="";

		 String date  = Integer.toString(now2.getDate());
		 String month = Integer.toString(now2.getMonth()+1);
		 String year  = Integer.toString(now2.getYear()+1900);
		 String hour = Integer.toString(now2.getHours());
		 String minute = Integer.toString(now2.getMinutes());
		 String second = Integer.toString(now2.getSeconds());

		 long msTime = now2.getTime();
		 int remdr = (int) ( msTime % ( 24L * 60 * 60 * 1000 ) );
		 remdr %= 60 * 60 * 1000;
		 remdr %= 60 * 1000;
		 String ms = Integer.toString(remdr % 1000);
		 
		 
		
		 if(ms.length()==1)ms = ".00"+ms;
		 else if(ms.length()==2)ms = ".0"+ms;
		 else ms = "."+ms;
		 
		 if(hour.length()==1)hour = "0"+hour;
		 if(minute.length()==1)minute = "0"+minute;
		 if(second.length()==1)second = "0"+second;
		 if(date.length()==1)date = "0"+date;
		 if(month.length()==1)month = "0"+month;
		 
		 
		 dateStr +=year;
		 dateStr +=month;
		 dateStr +=date;
		 dateStr +=hour;
		 dateStr +=minute;
		 dateStr +=second;
		 dateStr +=ms;

		 return dateStr;
	}

	public static String convertStrToTmsStr(String dbl){
		String tms="";
		tms += dbl.substring(0, 4);
		tms += "-";
		tms += dbl.substring(4, 6);
		tms += "-";
		tms += dbl.substring(6, 8);
		tms += " ";
		tms += dbl.substring(8, 10);
		tms += ":";
		tms += dbl.substring(10, 12);
		tms += ":";
		tms += dbl.substring(12, 14);
		tms += ":";
		tms += dbl.substring(15, 18);
		return tms;
	}
	
	public static String convertTimestampToString(Timestamp now2){
		 String curTime =""; 
		 String date  = Integer.toString(now2.getDate());
		 String month = Integer.toString(now2.getMonth()+1);
		 String year  = Integer.toString(now2.getYear()+1900);
		 String hour = Integer.toString(now2.getHours());
		 String minute = Integer.toString(now2.getMinutes());
		 String second = Integer.toString(now2.getSeconds());

		 long msTime = now2.getTime();
		 int remdr = (int) ( msTime % ( 24L * 60 * 60 * 1000 ) );
		 remdr %= 60 * 60 * 1000;
		 remdr %= 60 * 1000;
		 String ms = Integer.toString(remdr % 1000);
		 
		 if(hour.length()==1)hour = "0"+hour;
		 if(minute.length()==1)minute = "0"+minute;
		 if(second.length()==1)second = "0"+second;
		 if(date.length()==1)date = "0"+date;
		 if(month.length()==1)month = "0"+month;
			
	
			curTime +=year;
			curTime +="-";
			curTime +=month;
			curTime +="-";
			curTime +=date;
			curTime +=" ";
			curTime +=hour;
			curTime +=":";
			curTime +=minute;
			curTime +=":";
			curTime +=second;
			curTime +=":";
			curTime +=ms;
			
			return curTime;
		 
	}
	
	public String changeStringToDateFormatJPMC(String date){
		String year = date.substring(0, 4);
		String month = date.substring(4, 6);
		String day = date.substring(6, 8);
		String hour = date.substring(8,10);
		String minute = date.substring(10,12);
		String second = date.substring(12, 14);
		String milli = date.substring(14, 17);
		return year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second+":"+milli;
	}
	
	public String changeStringToDateFormatTCD(String date){
		String year = date.substring(0, 4);
		String month = date.substring(4, 6);
		String day = date.substring(6, 8);
		String hour = date.substring(8,10);
		String minute = date.substring(10,12);
		String second = date.substring(12, 14);
		return year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second+":000";
	}
}
